<?php 

namespace App\Http\Controllers\Admin;


use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Admin\ThrottlesLogins;
use Illuminate\Foundation\Admin\AuthenticatesAndRegistersUsers;
use Illuminate\Http\Request;
use App\Http\Requests;
use DB;


class AdminController extends Controller
{
	public $model=false;

	public function __construct(){
	     $this->model = new \App\Admin(); 
	}
    // public function index(){
   	// 	return view('Admin/index');
    // }
    //管理员添加
	public function admin_add(){
		if($_POST){
			$res=$this->model->add($_POST);
			if($res){
				echo '<script>alert("添加管理员成功");window.location.href="admin_list";</script>';
			}else{
				echo '<script>alert("添加管理员失败");window.location.href="admin_add";</script>';
			}
		}else{
			return view('Admin/admin/admin_add');
		}
	}


	//管理员列表
	public function admin_list(){
		$info= $this->model->lists();
		return view('Admin/admin/admin_list',['info'=>$info]);
	}

	//管理员状态改变
	public function admin_del($admin_id){
		$res=$this->model->del($admin_id);
		if($res!=0){
			return redirect('/admin/admin_list');
		}else{
			echo '禁用失败'; 
		}
	}
	//管理员状态还原
	public function admin_back($admin_id){
	   	$res=$this->model->back($admin_id);
	   	if($res!=0){
	   		return redirect('/admin/admin_list');
	   	}else{
	   		return '<script>alert("还原失败");location.href="admin_list";</script>';
	   	}
	}
	//给管理员分配权限
	public function set_node($admin_id){
		$admin_one=$this->model->getOne($admin_id);
		$nodeList=$this->model->SetNode($admin_id);
		// echo '<pre>';
		// print_r($nodeList);die;
		return view('Admin/admin/set_node',['nodeList'=>$nodeList,'admin_one'=>$admin_one]);
	}
	//添加权限
	public function add_Node(){
		$data = $_POST;
		$res=$this->model->AddNode($data);
		if($res){
			return '<script>alert("设置权限成功");location.href="admin_list";</script>';
		}else{
			return '<script>alert("设置权限失败");location.href="admin_list";</script>';
		}
	}


}



 ?>

